Skip to content

Introduce storage format v2 with aligned binary data and little-endian indexes - #1

Merged
n1k0m0 merged 1 commit into
mainfrom
codex/storage-format-v2-20261124
Nov 24, 2026
Merged

n1k0m0 merged 1 commit into
mainfrom
codex/storage-format-v2-20261124

Conversation

@n1k0m0

@n1k0m0 n1k0m0 commented Nov 24, 2026

Copy link
Copy Markdown
Member

Problem

The physical storage layout differed from the documented expectations in five places: REAL/DOUBLE values were decimal text, records were unaligned, user tables lacked metadata page 0, overflow pointers stored an eight-byte length, and numeric index components used big-endian ordering tricks.

This change introduces incompatible storage format 2. Existing format-1 databases are explicitly rejected; no legacy reader or automatic migration is provided.

Changes

  • Store both REAL and DOUBLE as exact finite IEEE-754 binary64 little-endian values, retaining their existing logical precision.
  • Align row starts and lengths to eight bytes, naturally align fixed-width fields, and validate every padding byte.
  • Reserve logical page 0 of every user table for a checksummed, immutable MSTB header. Heap and overflow pages start at 1; all physical table opens validate the header.
  • Store overflow length as U32 at pointer offset 24. Keep the pointer at 48 bytes for aligned U64 identifiers, with explicit zero padding and a pointer CRC-32C.
  • Encode typed numeric SQL index components in little-endian and compare them semantically, preserving signed integer ordering, floating ranges, composite keys, uniqueness and covering scans.
  • Preserve signed zero through SQL conversion, persisted keys and INCLUDE values. Covered equality scans return stored key bytes instead of reconstructing them from the search literal.
  • Centralize format identities, update configuration and compatibility documentation, and register a focused test.ps1 -StorageV2 gate in the cumulative storage phase.

Generic page, superblock and WAL framing, and the wire protocol remain version 1. This is an unreleased development change; the product version label is unchanged.

Validation

  • 5/5 new format suites passed in the final native Linux gate: metadata, rows, table headers, overflow and indexes.
  • 17 existing native Linux suites passed, covering configuration/catalog, heap/overflow/B+tree, WAL/transactions/recovery, SQL/schema evolution, VACUUM/REINDEX, page-size migration, database contracts and encrypted backup/restore. SQL and index integration were rerun after the final signed-zero fix.
  • All 4 static acceptance phases passed, including independent Python byte/CRC reference vectors; git diff --check is clean.
  • Windows x64 row/float regression compiled successfully with the expected CRT imports. It was not executed on Windows; the historical full 106-phase Windows release gate was not rerun.

Compiler: MiniLang 1.3.10, commit 8e64c9cfda92199b68ac5d3974fea445f12f6c39.

Format specification · Validation report

Store REAL/DOUBLE as binary64LE, align rows and scalar fields, reserve table page 0 for immutable metadata, use U32 overflow lengths, and compare typed little-endian index keys numerically.

Preserve signed zero through SQL conversion and covering indexes. Reject legacy database formats explicitly. Add byte-level regression tests, native test runner integration, and current format/compatibility documentation.
@n1k0m0
n1k0m0 marked this pull request as ready for review November 24, 2026 21:45
@n1k0m0
n1k0m0 merged commit 9bedab0 into main Nov 24, 2026
@n1k0m0
n1k0m0 deleted the codex/storage-format-v2-20261124 branch November 24, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant